
package br.com.danilloguimaraes.serializacao.xml;

import br.com.danilloguimaraes.serializacao.Sedes;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 *
 * @author danillo
 */
public class SedesXML implements Sedes{

    public void write(Object value, String path) throws FileNotFoundException {
        XMLEncoder xmle = new XMLEncoder( new BufferedOutputStream(new FileOutputStream(path)));
        xmle.writeObject(value);
        xmle.close();
    }

    public Object load(String path) throws FileNotFoundException {
        XMLDecoder decoder = new XMLDecoder(new FileInputStream(path));
        Object value = decoder.readObject();
        decoder.close();
        return value;
    }
    
}
